package chapter6;


import java.util.Arrays;

class Panda {
    private int age;

    public Panda(int age) {
        this.age = age;
    }

    public Panda() {
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
}

/**
 * final修饰引用类型变量，只保证其指向的地址不变
 */
public class FinalReferenceTest {
    public static void main(String[] args) {
        final int[] iArr = new int[]{5,6,12,9};
        System.out.println(Arrays.toString(iArr));
        Arrays.sort(iArr);
        System.out.println(Arrays.toString(iArr));
        iArr[2] = -8;
        System.out.println(Arrays.toString(iArr));
        //下面的语句非法，因为改变了引用变量的指向
        //iArr = null;
        final Panda p = new Panda(45);
        p.setAge(23);
        System.out.println(p.getAge());
        //同上，改变对象指向，非法
        //p = null;
    }
}
